<template>
  <div class="page-miH  page-bgBack">
    <PageHeader @back="goback" subTitle="返回">调岗记录</PageHeader>

    <div class="table m24">
      <a-input-search class="mb24" placeholder="搜索员工姓名" style="width: 180px" v-model="empName" @search="onSearch" />
      <a-table
        :row-selection="{
          selectedRowKeys: selectedRowKeys,
          onChange: onSelectChange
        }"
        :columns="columns"
        :row-key="record => record.id"
        :data-source="data"
        :pagination="pagination"
        size="middle"
        @change="handleTableChange"
      >
        <template slot="operate" slot-scope="text, record">
          <a-button size="small" type="link" @click="detail(record)">查看</a-button>
        </template>
      </a-table>
    </div>
  </div>
</template>
<script>
import { getEmpTransferList } from "@/api/staff/staff";
import { formatDate } from "@/utils/index";
const columns = [
  { title: "姓名", dataIndex: "empName" },

  { title: "手机号", dataIndex: "phone" },
  {
    title: "调岗日期",
    dataIndex: "adjustmentDate",
    customRender: (text, record, index) => {
      return formatDate(text);
    }
  },
  { title: "调岗原因", dataIndex: "adjustmentReason" },

  {
    title: "操作",
    dataIndex: "operate",
    scopedSlots: { customRender: "operate" }
  }
];

const pagination = {
  pageSize: 10,
  total: 0,
  size: "default",
  current: 1,
  showTotal: total => `共 ${total} 条`,
  showQuickJumper: true
};

export default {
  name: "LeaveList",
  // props: {
  //   selectId: {
  //     type: String,
  //     required: true
  //   },
  //   moveTag: {
  //     type: Boolean,
  //     required: true
  //   }
  // },
  data() {
    return {
      columns,
      empName: "",
      pagination,
      data: [],
      selectedRowKeys: []
    };
  },
  created() {
    this.getEmpInfosData();
  },
  methods: {
    onSearch() {
      this.pagination.current = 1;
      this.getEmpInfosData();
    },
    handleTableChange(pagination, filters, sorter) {
      this.pagination.current = pagination.current;
      this.getEmpInfosData();
    },
    getEmpInfosData() {
      getEmpTransferList(this.$store.state.hr.companyId, {
        empName: this.empName,
        pageNo: this.pagination.current,
        pageSize: 10
      }).then(res => {
        this.pagination.total = res.data && res.data.entityCount;
        this.data = res.data.entities;
      });
    },
    onSelectChange(selectedRowKeys) {
      this.selectedRowKeys = selectedRowKeys;
    },
    goback() {
      this.$router.push({
        path: "/staff/manger?selectId=5"
      });
    },
    detail: function(row) {
      const searchData = {
        companyId: this.$store.state.hr.companyId,
        queryType: 7
      };
      this.$router.push({
        path: "/staff/detail",
        query: {
          id: row.empId,
          userId: row.userId,
          prevpage: location.hash.slice(1)
        }
      });
    }
  }
};
</script>
